import store from "@/store";

export default {
  inserted(el, bindling) {
    const permission = store.getters.permission || {}
    let hasPermission = false
    const value = bindling.value
    if (typeof(value) === 'string') {
      hasPermission = permission[value]
    } else if (value instanceof Array) {
      hasPermission = value.some(item => permission[item])
    }

    if (!value) {// 权限值为空时，有权限
      hasPermission = true
    }
    if (!hasPermission) {
      const vm = el.__vue__;
      vm && vm.$destroy();
      el.style.display = "none";
      el.remove && el.remove();
    }
  }
};
